package com.community.backend.controller;

import com.community.backend.pojo.Patrol;
import com.community.backend.pojo.dto.PatrolQueryDTO;
import com.community.backend.service.PatrolService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/patrol")
public class PatrolController {
    private final PatrolService patrolService;

    public PatrolController(PatrolService patrolService) {
        this.patrolService = patrolService;
    }

    @GetMapping("/page")
    public Result<PageResult> page(PatrolQueryDTO patrolQueryDTO) {
        log.info("巡察信息：{}", patrolQueryDTO);
        PageResult pageResult = patrolService.pageQuery(patrolQueryDTO);
        return Result.success(pageResult);
    }
    @PutMapping
    public Result update(@RequestBody Patrol patrol){
        log.info("修改巡察信息参数：{}", patrol);
        patrolService.update(patrol);
        return Result.success();
    }
    @PostMapping
    public Result save(@RequestBody Patrol patrol){
        patrolService.save(patrol);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result patrolDetail(@PathVariable Integer id){
        Patrol patrol = patrolService.selectById(id);
        return Result.success(patrol);
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        patrolService.deleteById(id);
        return Result.success();
    }
}
